// obj2sql(router_lis)
// 返回菜单数据，反向生成相关表格更新sql语句

function Guid() {
  function N() {
    return ((Math.random() * 0x1000000) | 0).toString(16).toLocaleUpperCase().substring(0, 5)
  }
  return `${N()}-${N()}-${N()}-${N()}-${N()}`
}

function convert(lis, parentid) {
  let out = ''
  for (let item of lis) {
    let gid = Guid()
    out += `insert into funcList (
      funcId,
      parentId,
      path,
      component,
      redirect,
      funcName,
      title,
      icon
    ) values(
      '${gid}',
      '${parentid}',
      '${item.path || ''}',
      '${item.component || ''}',
      '${item.redirect || ''}',
      '${item.name || ''}',
      '${item.meta && item.meta.title ? item.meta.title : ''}',
      '${item.meta && item.meta.icon ? item.meta.icon : ''}'
    );
    `
    if (item.children) out += convert(item.children, gid)
  }
  return out
}

const t = require('../mock/routeBase')
// console.log(t)

console.log(JSON.stringify(t))

// let res = convert(t, '00000-00000-00000-00000-00000')
// console.log(res.replace(/\n| {2}/g, '').replace(/;/g, '\n'))
